﻿using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomPropertyDrawer(typeof(PUEXDynamicTrigger))]
public class PUEXDynamicAttributeTriggerDrawer : PropertyDrawer {
	
	public override float GetPropertyHeight (SerializedProperty property, GUIContent label) 
	{
		return 18f * 2;
	}
	
	public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 
	{
		var triggerBaseValueParamNameProperty = property.FindPropertyRelative ("triggerBaseValueParamName");
		var triggerScaleValueParamNameProperty = property.FindPropertyRelative ("triggerScaleValueParamName");
		var baseValueProperty = property.FindPropertyRelative ("baseValue");
		var scaleValueProperty = property.FindPropertyRelative ("scaleValue");
		var curveProperty = property.FindPropertyRelative ("curve");
		
		label = EditorGUI.BeginProperty(position, label, property);
		Rect contentPosition = EditorGUI.PrefixLabel(position, label);
		
//		EditorGUI.indentLevel = 1;
//		position = EditorGUI.IndentedRect(position);
		EditorGUIUtility.labelWidth = 7f * 5;
		contentPosition.width = position.width / 6; contentPosition.height = 18f;
		
		contentPosition.x = position.x; contentPosition.y = position.y + 18f; 
		EditorGUI.PropertyField(contentPosition, baseValueProperty, new GUIContent("base"));
		contentPosition.x += contentPosition.width;
		EditorGUI.PropertyField(contentPosition, triggerBaseValueParamNameProperty, new GUIContent(" <--"));
		
		contentPosition.x += contentPosition.width;
		EditorGUI.PropertyField(contentPosition, scaleValueProperty, new GUIContent("scale"));
		contentPosition.x += contentPosition.width;
		EditorGUI.PropertyField(contentPosition, triggerScaleValueParamNameProperty, new GUIContent(" <--"));

		contentPosition.x += contentPosition.width + 7f; contentPosition.width = position.width / 3 - 7f;
		EditorGUI.CurveField(contentPosition, curveProperty, Color.yellow, Rect.MinMaxRect(0f, -1f, 1f, 1f));
		
		EditorGUI.EndProperty();
	}
	
}
